package ln.gather.jsr.jndi.function;

import static ln.gather.jsr.jndi.utils.ExceptionUtils.wrapThrowable;

@FunctionalInterface
public interface ThrowableAction {

    void execute() throws Throwable;

    static void execute(ThrowableAction action) throws RuntimeException {
        execute(action, RuntimeException.class);
    }

    static <T extends Throwable> void execute(ThrowableAction action, Class<T> throwableType) throws T {
        try {
            action.execute();
        } catch (Throwable e) {
            throw wrapThrowable(e, throwableType);
        }
    }


}
